package com.shop.service.module.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.service.module.entity.GoodsEntity;
import com.shop.service.module.entity.Result;
import com.shop.service.module.mapper.GoodsMapper;
import com.shop.service.module.service.GoodsService;
import org.springframework.stereotype.Service;

@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, GoodsEntity> implements GoodsService {
    @Override
    public Result getGoodsListForPage(int pno, int psize, String name, Long goodsTypeId, Integer isOnSale) {
        System.out.println("jinrul");
        Page<GoodsEntity> p = new Page<>(pno,psize);
        Page<GoodsEntity> result = baseMapper.getGoodsListForPage(p, name, goodsTypeId, isOnSale);
        JSONObject data = new JSONObject();
        JSONObject jsonResult = new JSONObject();
        jsonResult.put("pno", pno);
        jsonResult.put("psize", psize);
        jsonResult.put("pCount", result.getPages());
        jsonResult.put("totalElements", result.getTotal());
        data.put("list", result.getRecords());
        data.put("page", jsonResult);
        return Result.end(200, data, "查询成功");
    }

}
